//index.js
//获取应用实例
const app = getApp()

import {
  get,
  post
} from '../../utils/api'

Page({
  data: {
    active: 0,
    selected: 'a',
    color: ['blue', 'green', 'red'],
    dataList: [],
    twoDataList: '',
    allList: [],
    oneFloorList: [],
    twoFloorList: []

  },
  //事件处理函数
  floorClick({
    currentTarget: {
      dataset: {
        name
      }
    }
  }) {
    this.setData({
      dataList: name==0?this.data.allList: this.data.allList.filter(i => i.deskSort == name),
      active: name,
      selected: 'a',
      twoDataList: ''
    })
  },

  tabClick({
    currentTarget: {
      dataset: {
        name
      }
    }
  }) {
    if (name == 'a') {
      this.setData({
        twoDataList: this.data.dataList
      })
    } else if (name == 'b') {
      this.setData({
        twoDataList: this.data.dataList.filter(i => i.deskstatus == 0)
      })
    } else if (name == 'c') {
      this.setData({
        twoDataList: this.data.dataList.filter(i => i.deskstatus == 1 || i.deskstatus == 2)
      })
    } else {
      this.setData({
        twoDataList: []
      })
    }
    this.setData({
      selected: name
    })
  },

  onLoad: async function () {
const {data:{data}} = await get('http://192.168.35.43:82/desk/findAll')
console.log(data);
this.setData({
  dataList:data,
  allList:data
})
  },

  goOrder({
    currentTarget: {
      dataset: {
        id
      }
    }
  }){
    console.log(id)
    if(id.deskstatus==0){
      wx.switchTab({
        url: `/pages/order/order`,
      })
    }
    wx.setStorageSync('deedNum', id.deskname)
  }
})